package com.zqg8512.server.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author zengqianggang
 * @Description //TODO
 * Author VPN
 * @Date 2019/9/5 16:37
 * @Version 1.0
 **/
@Component
public class NettyServer {

    @Value(value="${remote.ip}")
    private String ip;

    @Value("${remote.port}")
    private Integer port;

    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(NettyServer.class);

    public String start(){

        LOGGER.info("服务器运行 {}:{}",ip,port);

        final NioEventLoopGroup boss=new NioEventLoopGroup();
        final NioEventLoopGroup worker=new NioEventLoopGroup();

        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(boss,worker)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG,1024)
                .childOption(ChannelOption.SO_KEEPALIVE,true);
                // .childHandler()


        return ip + ":" + port;
    }



}
